<template>
    <div ref="printRef" v-show="show || isPrint">
        <slot></slot>
    </div>
</template>

<script>
export default {
    props: {
        show: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            isPrint: false,
        }
    },
    methods: {
        print() {
            this.isPrint = true
            setTimeout(() => {
                document.body.appendChild(this.$refs.printRef);
                window.print()
                document.body.removeChild(this.$refs.printRef);
                this.isPrint = false
            }, 0)
        },
        preview() {
            this.isPrint = true
            setTimeout(() => {
                document.body.appendChild(this.$refs.printRef);
            }, 0)
        }
    }
}
</script>

<style lang="scss" scoped></style>